package com.jichangxiu.common.exception;

import com.jichangxiu.common.enums.ErrorType;
import lombok.*;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ServiceException extends RuntimeException implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code;

    private String message;

    public ServiceException(String message) {
        super(message);
        this.code = ErrorType.SERVICE_EXCEPTION.getCode();
        this.message = message;
    }

    public ServiceException(String message, Throwable throwable) {
        super(message, throwable);
        this.code = ErrorType.SERVICE_EXCEPTION.getCode();
        this.message = message;
    }

    public ServiceException(ErrorType errorType) {
        super(errorType.getMessage());
        this.code = errorType.getCode();
        this.message = errorType.getMessage();
    }

    public ServiceException(ErrorType errorType, Throwable throwable) {
        super(errorType.getMessage(), throwable);
        this.code = errorType.getCode();
        this.message = errorType.getMessage();
    }

}
